home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libblas / src_original / sgemm.f < prev    next >
Encoding:
Text File  |  1994-08-02  |  10.9 KB  |  349 lines

  1. *
  2. ************************************************************************
  3. *
  4. *     File of the REAL             Level-3 BLAS.
  5. *     ==========================================
  6. *
  7. *     SUBROUTINE SGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,
  8. *    $                   BETA, C, LDC )
  9. *
  10. *     SUBROUTINE SSYMM ( SIDE,   UPLO,   M, N,    ALPHA, A, LDA, B, LDB,
  11. *    $                   BETA, C, LDC )
  12. *
  13. *     SUBROUTINE SSYRK ( UPLO,   TRANS,     N, K, ALPHA, A, LDA,
  14. *    $                   BETA, C, LDC )
  15. *
  16. *     SUBROUTINE SSYR2K( UPLO,   TRANS,     N, K, ALPHA, A, LDA, B, LDB,
  17. *    $                   BETA, C, LDC )
  18. *
  19. *     SUBROUTINE STRMM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA,
  20. *    $                   B, LDB )
  21. *
  22. *     SUBROUTINE STRSM ( SIDE, UPLO, TRANSA, DIAG, M, N, ALPHA, A, LDA,
  23. *    $                   B, LDB )
  24. *
  25. *     See:
  26. *
  27. *        Dongarra J. J.,   Du Croz J. J.,   Duff I.  and   Hammarling S.
  28. *        A set of  Level 3  Basic Linear Algebra Subprograms.  Technical
  29. *        Memorandum No.88 (Revision 1), Mathematics and Computer Science
  30. *        Division,  Argonne National Laboratory, 9700 South Cass Avenue,
  31. *        Argonne, Illinois 60439.
  32. *
  33. *
  34. ************************************************************************
  35. *
  36.       SUBROUTINE SGEMM ( TRANSA, TRANSB, M, N, K, ALPHA, A, LDA, B, LDB,
  37.      $                   BETA, C, LDC )
  38. *     .. Scalar Arguments ..
  39.       CHARACTER*1        TRANSA, TRANSB
  40.       INTEGER            M, N, K, LDA, LDB, LDC
  41.       REAL               ALPHA, BETA
  42. *     .. Array Arguments ..
  43.       REAL               A( LDA, * ), B( LDB, * ), C( LDC, * )
  44. *     ..
  45. *
  46. *  Purpose
  47. *  =======
  48. *
  49. *  SGEMM  performs one of the matrix-matrix operations
  50. *
  51. *     C := alpha*op( A )*op( B ) + beta*C,
  52. *
  53. *  where  op( X ) is one of
  54. *
  55. *     op( X ) = X   or   op( X ) = X',
  56. *
  57. *  alpha and beta are scalars, and A, B and C are matrices, with op( A )
  58. *  an m by k matrix,  op( B )  a  k by n matrix and  C an m by n matrix.
  59. *
  60. *  Parameters
  61. *  ==========
  62. *
  63. *  TRANSA - CHARACTER*1.
  64. *           On entry, TRANSA specifies the form of op( A ) to be used in
  65. *           the matrix multiplication as follows:
  66. *
  67. *              TRANSA = 'N' or 'n',  op( A ) = A.
  68. *
  69. *              TRANSA = 'T' or 't',  op( A ) = A'.
  70. *
  71. *              TRANSA = 'C' or 'c',  op( A ) = A'.
  72. *
  73. *           Unchanged on exit.
  74. *
  75. *  TRANSB - CHARACTER*1.
  76. *           On entry, TRANSB specifies the form of op( B ) to be used in
  77. *           the matrix multiplication as follows:
  78. *
  79. *              TRANSB = 'N' or 'n',  op( B ) = B.
  80. *
  81. *              TRANSB = 'T' or 't',  op( B ) = B'.
  82. *
  83. *              TRANSB = 'C' or 'c',  op( B ) = B'.
  84. *
  85. *           Unchanged on exit.
  86. *
  87. *  M      - INTEGER.
  88. *           On entry,  M  specifies  the number  of rows  of the  matrix
  89. *           op( A )  and of the  matrix  C.  M  must  be at least  zero.
  90. *           Unchanged on exit.
  91. *
  92. *  N      - INTEGER.
  93. *           On entry,  N  specifies the number  of columns of the matrix
  94. *           op( B ) and the number of columns of the matrix C. N must be
  95. *           at least zero.
  96. *           Unchanged on exit.
  97. *
  98. *  K      - INTEGER.
  99. *           On entry,  K  specifies  the number of columns of the matrix
  100. *           op( A ) and the number of rows of the matrix op( B ). K must
  101. *           be at least  zero.
  102. *           Unchanged on exit.
  103. *
  104. *  ALPHA  - REAL            .
  105. *           On entry, ALPHA specifies the scalar alpha.
  106. *           Unchanged on exit.
  107. *
  108. *  A      - REAL             array of DIMENSION ( LDA, ka ), where ka is
  109. *           k  when  TRANSA = 'N' or 'n',  and is  m  otherwise.
  110. *           Before entry with  TRANSA = 'N' or 'n',  the leading  m by k
  111. *           part of the array  A  must contain the matrix  A,  otherwise
  112. *           the leading  k by m  part of the array  A  must contain  the
  113. *           matrix A.
  114. *           Unchanged on exit.
  115. *
  116. *  LDA    - INTEGER.
  117. *           On entry, LDA specifies the first dimension of A as declared
  118. *           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
  119. *           LDA must be at least  max( 1, m ), otherwise  LDA must be at
  120. *           least  max( 1, k ).
  121. *           Unchanged on exit.
  122. *
  123. *  B      - REAL             array of DIMENSION ( LDB, kb ), where kb is
  124. *           n  when  TRANSB = 'N' or 'n',  and is  k  otherwise.
  125. *           Before entry with  TRANSB = 'N' or 'n',  the leading  k by n
  126. *           part of the array  B  must contain the matrix  B,  otherwise
  127. *           the leading  n by k  part of the array  B  must contain  the
  128. *           matrix B.
  129. *           Unchanged on exit.
  130. *
  131. *  LDB    - INTEGER.
  132. *           On entry, LDB specifies the first dimension of B as declared
  133. *           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
  134. *           LDB must be at least  max( 1, k ), otherwise  LDB must be at
  135. *           least  max( 1, n ).
  136. *           Unchanged on exit.
  137. *
  138. *  BETA   - REAL            .
  139. *           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
  140. *           supplied as zero then C need not be set on input.
  141. *           Unchanged on exit.
  142. *
  143. *  C      - REAL             array of DIMENSION ( LDC, n ).
  144. *           Before entry, the leading  m by n  part of the array  C must
  145. *           contain the matrix  C,  except when  beta  is zero, in which
  146. *           case C need not be set on entry.
  147. *           On exit, the array  C  is overwritten by the  m by n  matrix
  148. *           ( alpha*op( A )*op( B ) + beta*C ).
  149. *
  150. *  LDC    - INTEGER.
  151. *           On entry, LDC specifies the first dimension of C as declared
  152. *           in  the  calling  (sub)  program.   LDC  must  be  at  least
  153. *           max( 1, m ).
  154. *           Unchanged on exit.
  155. *
  156. *
  157. *  Level 3 Blas routine.
  158. *
  159. *  -- Written on 8-February-1989.
  160. *     Jack Dongarra, Argonne National Laboratory.
  161. *     Iain Duff, AERE Harwell.
  162. *     Jeremy Du Croz, Numerical Algorithms Group Ltd.
  163. *     Sven Hammarling, Numerical Algorithms Group Ltd.
  164. *
  165. *
  166. *     .. External Functions ..
  167.       LOGICAL            LSAME
  168.       EXTERNAL           LSAME
  169. *     .. External Subroutines ..
  170.       EXTERNAL           XERBLA
  171. *     .. Intrinsic Functions ..
  172.       INTRINSIC          MAX
  173. *     .. Local Scalars ..
  174.       LOGICAL            NOTA, NOTB
  175.       INTEGER            I, INFO, J, L, NCOLA, NROWA, NROWB
  176.       REAL               TEMP
  177. *     .. Parameters ..
  178.       REAL               ONE         , ZERO
  179.       PARAMETER        ( ONE = 1.0E+0, ZERO = 0.0E+0 )
  180. *     ..
  181. *     .. Executable Statements ..
  182. *
  183. *     Set  NOTA  and  NOTB  as  true if  A  and  B  respectively are not
  184. *     transposed and set  NROWA, NCOLA and  NROWB  as the number of rows
  185. *     and  columns of  A  and the  number of  rows  of  B  respectively.
  186. *
  187.       NOTA  = LSAME( TRANSA, 'N' )
  188.       NOTB  = LSAME( TRANSB, 'N' )
  189.       IF( NOTA )THEN
  190.          NROWA = M
  191.          NCOLA = K
  192.       ELSE
  193.          NROWA = K
  194.          NCOLA = M
  195.       END IF
  196.       IF( NOTB )THEN
  197.          NROWB = K
  198.       ELSE
  199.          NROWB = N
  200.       END IF
  201. *
  202. *     Test the input parameters.
  203. *
  204.       INFO = 0
  205.       IF(      ( .NOT.NOTA                 ).AND.
  206.      $         ( .NOT.LSAME( TRANSA, 'C' ) ).AND.
  207.      $         ( .NOT.LSAME( TRANSA, 'T' ) )      )THEN
  208.          INFO = 1
  209.       ELSE IF( ( .NOT.NOTB                 ).AND.
  210.      $         ( .NOT.LSAME( TRANSB, 'C' ) ).AND.
  211.      $         ( .NOT.LSAME( TRANSB, 'T' ) )      )THEN
  212.          INFO = 2
  213.       ELSE IF( M  .LT.0               )THEN
  214.          INFO = 3
  215.       ELSE IF( N  .LT.0               )THEN
  216.          INFO = 4
  217.       ELSE IF( K  .LT.0               )THEN
  218.          INFO = 5
  219.       ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
  220.          INFO = 8
  221.       ELSE IF( LDB.LT.MAX( 1, NROWB ) )THEN
  222.          INFO = 10
  223.       ELSE IF( LDC.LT.MAX( 1, M     ) )THEN
  224.          INFO = 13
  225.       END IF
  226.       IF( INFO.NE.0 )THEN
  227.          CALL XERBLA( 'SGEMM ', INFO )
  228.          RETURN
  229.       END IF
  230. *
  231. *     Quick return if possible.
  232. *
  233.       IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.
  234.      $    ( ( ( ALPHA.EQ.ZERO ).OR.( K.EQ.0 ) ).AND.( BETA.EQ.ONE ) ) )
  235.      $   RETURN
  236. *
  237. *     And if  alpha.eq.zero.
  238. *
  239.       IF( ALPHA.EQ.ZERO )THEN
  240.          IF( BETA.EQ.ZERO )THEN
  241.             DO 20, J = 1, N
  242.                DO 10, I = 1, M
  243.                   C( I, J ) = ZERO
  244.    10          CONTINUE
  245.    20       CONTINUE
  246.          ELSE
  247.             DO 40, J = 1, N
  248.                DO 30, I = 1, M
  249.                   C( I, J ) = BETA*C( I, J )
  250.    30          CONTINUE
  251.    40       CONTINUE
  252.          END IF
  253.          RETURN
  254.       END IF
  255. *
  256. *     Start the operations.
  257. *
  258.       IF( NOTB )THEN
  259.          IF( NOTA )THEN
  260. *
  261. *           Form  C := alpha*A*B + beta*C.
  262. *
  263.             DO 90, J = 1, N
  264.                IF( BETA.EQ.ZERO )THEN
  265.                   DO 50, I = 1, M
  266.                      C( I, J ) = ZERO
  267.    50             CONTINUE
  268.                ELSE IF( BETA.NE.ONE )THEN
  269.                   DO 60, I = 1, M
  270.                      C( I, J ) = BETA*C( I, J )
  271.    60             CONTINUE
  272.                END IF
  273.                DO 80, L = 1, K
  274.                   IF( B( L, J ).NE.ZERO )THEN
  275.                      TEMP = ALPHA*B( L, J )
  276.                      DO 70, I = 1, M
  277.                         C( I, J ) = C( I, J ) + TEMP*A( I, L )
  278.    70                CONTINUE
  279.                   END IF
  280.    80          CONTINUE
  281.    90       CONTINUE
  282.          ELSE
  283. *
  284. *           Form  C := alpha*A'*B + beta*C
  285. *
  286.             DO 120, J = 1, N
  287.                DO 110, I = 1, M
  288.                   TEMP = ZERO
  289.                   DO 100, L = 1, K
  290.                      TEMP = TEMP + A( L, I )*B( L, J )
  291.   100             CONTINUE
  292.                   IF( BETA.EQ.ZERO )THEN
  293.                      C( I, J ) = ALPHA*TEMP
  294.                   ELSE
  295.                      C( I, J ) = ALPHA*TEMP + BETA*C( I, J )
  296.                   END IF
  297.   110          CONTINUE
  298.   120       CONTINUE
  299.          END IF
  300.       ELSE
  301.          IF( NOTA )THEN
  302. *
  303. *           Form  C := alpha*A*B' + beta*C
  304. *
  305.             DO 170, J = 1, N
  306.                IF( BETA.EQ.ZERO )THEN
  307.                   DO 130, I = 1, M
  308.                      C( I, J ) = ZERO
  309.   130             CONTINUE
  310.                ELSE IF( BETA.NE.ONE )THEN
  311.                   DO 140, I = 1, M
  312.                      C( I, J ) = BETA*C( I, J )
  313.   140             CONTINUE
  314.                END IF
  315.                DO 160, L = 1, K
  316.                   IF( B( J, L ).NE.ZERO )THEN
  317.                      TEMP = ALPHA*B( J, L )
  318.                      DO 150, I = 1, M
  319.                         C( I, J ) = C( I, J ) + TEMP*A( I, L )
  320.   150                CONTINUE
  321.                   END IF
  322.   160          CONTINUE
  323.   170       CONTINUE
  324.          ELSE
  325. *
  326. *           Form  C := alpha*A'*B' + beta*C
  327. *
  328.             DO 200, J = 1, N
  329.                DO 190, I = 1, M
  330.                   TEMP = ZERO
  331.                   DO 180, L = 1, K
  332.                      TEMP = TEMP + A( L, I )*B( J, L )
  333.   180             CONTINUE
  334.                   IF( BETA.EQ.ZERO )THEN
  335.                      C( I, J ) = ALPHA*TEMP
  336.                   ELSE
  337.                      C( I, J ) = ALPHA*TEMP + BETA*C( I, J )
  338.                   END IF
  339.   190          CONTINUE
  340.   200       CONTINUE
  341.          END IF
  342.       END IF
  343. *
  344.       RETURN
  345. *
  346. *     End of SGEMM .
  347. *
  348.       END
  349.